<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    Integer totlenum = (Integer) session.getAttribute("totlenum");
    Integer curPage = (Integer) session.getAttribute("curPage");
    String cardnoFrom = (String) session.getAttribute("cardnoFrom");
    String cardnoTo = (String) session.getAttribute("cardnoTo");
    String batch = (String) session.getAttribute("batch");
    Integer choose = (Integer) session.getAttribute("choose");
    String oemUsername = (String) session.getAttribute("oemUsername");
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>随便打TCS系统</title>
    <script type="text/javascript" src="<%=basePath%>js/initPage.js"></script>
    <!-- Bootstrap -->
    <link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
          rel="stylesheet">
    <!-- Font Awesome -->
    <link
            href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
            rel="stylesheet">
    <!-- NProgress -->
    <link href="<%=basePath%>vendors/nprogress/nprogress.css"
          rel="stylesheet">
    <!-- iCheck -->
    <link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
          rel="stylesheet">

    <!-- bootstrap-progressbar -->
    <link
            href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
            rel="stylesheet">
    <!-- JQVMap -->
    <link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
          rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link
            href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
            rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">

</head>
<body class="nav-md">

<div id="huabodiv" class="white_content_small">
    <div style="text-align: right; cursor: default; height: 40px;">
        <span style="font-size: 16px;" onclick="CloseDiv('huabodiv','fade')">关闭</span>
    </div>
    <div class="item form-group">
        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">划拨商户
            <span class="required">*</span>
        </label>
        <div class="col-md-6 col-sm-6 col-xs-12">
            <c:if test="${choose == 1}">
                <input id="parentid" name="parentid" class="form-control col-md-7 col-xs-12"
                       type="text" value="${parentid}">
            </c:if>
            <c:if test="${choose == 2}">
                <input id="parentid" name="parentid" class="form-control col-md-7 col-xs-12"
                       type="text" value="${oemUsername}">
            </c:if>
        </div>
        <div class="form-group">
            <div class="col-md-6 col-md-offset-3">
                <a type="submit" class="btn btn-primary" href="javascript:void(0)"
                   onclick="CloseDiv('huabodiv','fade')">取消</a>
                <c:if test="${choose == 1}">
                    <a id="dialog" type="submit" class="btn btn-success" href="javascript:void(0)"
                       onclick="sendCards()">划拨</a>
                </c:if>
            </div>
        </div>
    </div>
</div>


<div id="fade" class="black_overlay"></div>
<div class="container body">
    <div class="main_container">
        <div class="col-md-3 left_col">
            <div class="left_col scroll-view">
                <div class="clearfix"></div>

                <br/>


            </div>
        </div>


        <!-- page content -->
        <div class="right_col" role="main">

            <div class="">
                <div class="page-title"></div>
                <div class="x_content">
                    <c:if test="${status == 0 || status == null}">
                        <select class="btn btn-default dropdown-toggle" id="status" style="text-align: center;">
                            <option value="0" selected="selected"> 全部</option>
                            <option value="1">未使用</option>
                            <option value="2">已充值</option>
                        </select>
                    </c:if>
                    <c:if test="${status == 1}">
                        <select class="btn btn-default dropdown-toggle" id="status" style="text-align: center;">
                            <option value="0"> 全部</option>
                            <option value="1" selected="selected">未使用</option>
                            <option value="2">已充值</option>
                        </select>
                    </c:if>
                    <c:if test="${status == 2}">
                        <select class="btn btn-default dropdown-toggle" id="status" style="text-align: center;">
                            <option value="0"> 全部</option>
                            <option value="1">未使用</option>
                            <option value="2" selected="selected">已充值</option>
                        </select>
                    </c:if>
                    所属商家: <input type="text"
                                 name="lname" id="pId" value="${pId}"/>
                    批次: <input type="text" name="lname" id="batch" value="${batch}"/>
                    卡号段查询: <input type="text" name="lname" id="cardnoFrom"
                                  value="${cardnoFrom}"/> —— <input type="text" name="lname"
                                                                    id="cardnoTo" value="${cardnoTo}"/>
                    <button type="submit" class="btn btn-default"
                            onclick="selectOEM(1)">搜索
                    </button>
                    <c:if test="${choose == 1}">
                        <button type="submit" class="btn btn-default"
                                onclick="ShowDiv('huabodiv','fade')">划拨搜索结果
                        </button>
                    </c:if>
                    <c:if test="${choose == 2}">
                        <button type="submit" class="btn btn-default"
                                onclick="huishou()">回收搜索结果
                        </button>
                    </c:if>
                    <a>共计${totlenum }张</a>
                </div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">

                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">


                                <table id="datatable"
                                       class="table table-striped table-bordered">

                                    <thead>
                                    <tr>
                                        <th>卡号</th>
                                        <th>卡密</th>
                                        <th>使用截至</th>
                                        <th>有效期截至</th>
                                        <th>批次</th>
                                        <th>面值</th>
                                        <th>费率组</th>
                                        <th>充值卡类型</th>
                                        <th>充值号码</th>
                                        <th>所属商</th>
                                    </tr>
                                    </thead>


                                    <tbody>
                                    <c:forEach items="${list}" var="s" varStatus="z">
                                        <tr>
                                            <div class="item form-group" style="display:none">
                                                <label class="control-label col-md-3 col-sm-3 col-xs-12"
                                                       for="name">id<span class="required"></span>
                                                </label>
                                                <div class="col-md-6 col-sm-6 col-xs-12">
                                                    <input id="id" name="id" class="form-control col-md-7 col-xs-12"
                                                           type="text" value="${s.id}">
                                                </div>
                                            </div>
                                            <td>${s.cardno}</td>
                                            <td>${s.pwd}</td>
                                            <td>${s.probationperiod}</td>
                                            <td>${s.termofvalidity}</td>
                                            <td>${s.batch}</td>
                                            <td>${s.money}</td>
                                            <td>${s.feelroute}</td>
                                            <td><c:if test="${s.type == 1 }">
                                                <span>月卡</span>
                                            </c:if> <c:if test="${s.type == 2 }">
                                                <span>季卡</span>
                                            </c:if> <c:if test="${s.type == 3 }">
                                                <span>年卡</span>
                                            </c:if> <c:if test="${s.type == 4 }">
                                                <span>面值卡</span>
                                            </c:if> <c:if test="${s.type == 5 }">
                                                <span>购物卡</span>
                                            </c:if></td>
                                            <td><c:if test="${s.mobile == null ||s.mobile ==''}">
                                                <span>该卡暂未充值</span>
                                            </c:if> <c:if test="${s.mobile != null }">
                                                <span>${s.mobile}</span>
                                            </c:if></td>
                                            <td>${s.users.username}</td>
                                        </tr>

                                    </c:forEach>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="width: 100%;text-align: center;">
                <div id='page'></div>
            </div>
        </div>

        <!-- /page content -->
    </div>
</div>
<style>
    .black_overlay {
        display: none;
        position: absolute;
        top: 0%;
        left: 0%;
        width: 100%;
        height: 100%;
        background-color: black;
        z-index: 1001;
        -moz-opacity: 0.8;
        opacity: .80;
        filter: alpha(opacity=80);
    }

    .white_content {
        display: none;
        position: absolute;
        top: 20%;
        left: 30%;
        width: 30%;
        height: 40%;
        border: 16px solid white;
        background-color: white;
        z-index: 1002;
        overflow: auto;
        left: 30%;
    }

    .white_content_small {
        display: none;
        position: absolute;
        top: 20%;
        left: 30%;
        width: 30%;
        height: 20%;
        border: 16px solid white;
        background-color: white;
        z-index: 1002;
        overflow: auto;
    }
</style>

<script src="<%=basePath%>vendors/download.js"></script>
<!-- jQuery -->
<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
<!-- NProgress -->
<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
<!-- bootstrap-daterangepicker -->
<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
<script src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
<!-- Chart.js -->
<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
<!-- Custom Theme Scripts -->
<script src="<%=basePath%>build/js/custom.min.js"></script>
<script>
    function sendCards() {
        var cardnoFrom = $("#cardnoFrom").val();
        var cardnoTo = $("#cardnoTo").val();
        var batch = $("#batch").val();
        var parentid = $("#parentid").val();

        $.ajax({
            type: "POST",
            url: "doSplitCards",
            data: {
                cardnoFrom:cardnoFrom,
                cardnoTo: cardnoTo,
                batch:batch,
                parentid:parentid
            },
            dataType: "text",
            success: function (data) {
                console.log(data);
                alert(data);
                selectOEM(1);
            }
        });
    }

    function selectOEM(curPage) {
        var cardnoFrom = $("#cardnoFrom").val();
        var cardnoTo = $("#cardnoTo").val();
        var pId = $("#pId").val();
        var batch = $("#batch").val();
        var choose = 1;
        var status = document.getElementById('status').value;
        location.href = "content_splitRechargeCards?curPage="
            + curPage +
            "&cardnoFrom=" + cardnoFrom +
            "&cardnoTo=" + cardnoTo +
            "&batch=" + batch +
            "&choose=" + choose +
            "&pId=" + pId;
    }

    /**
     * 纯粹的JS分页插件，代码缺点：JS操作DOM冗余太多，太繁琐
     */
    pageUtil.initPage('page', {
        totalCount: ${totlenum}, //总页数，一般从回调函数中获取。如果没有数据则默认为1页
        curPage: ${curPage}, //初始化时的默认选中页，默认第一页。如果所填范围溢出或者非数字或者数字字符串，则默认第一页
        showCount: 9, //分页栏显示的数量
        pageSizeList: [10], //自定义分页数，默认[5,10,15,20,50]
        defaultPageSize: 10, //默认选中的分页数,默认选中第一个。如果未匹配到数组或者默认数组中，则也为第一个
        isJump: true, //是否包含跳转功能，默认false
        isPageNum: true, //是否显示分页下拉选择，默认false
        isPN: true, //是否显示上一页和下一面，默认true
        isFL: true, //是否显示首页和末页，默认true
        jump: function (curPage, pageSize) { //跳转功能回调，传递回来2个参数，当前页和每页大小。如果没有设置分页下拉，则第二个参数永远为0。这里的this被指定为一个空对象，如果回调中需用到this请自行使用bind方法
            selectOEM(curPage);
        },
    });
</script>
<script>
    //弹出隐藏层
    function ShowDiv(show_div, bg_div) {
        // document.getElementById("shopmoney_box").style.display=(batch.value != null && batch.value != "")?"":"none";
        document.getElementById(show_div).style.display = 'block';
        document.getElementById(bg_div).style.display = 'block';
        var bgdiv = document.getElementById(bg_div);
        bgdiv.style.width = document.body.scrollWidth;
        // bgdiv.style.height = $(document).height();
        $("#" + bg_div).height($(document).height());
    }

    //关闭弹出层
    function CloseDiv(show_div, bg_div) {
        document.getElementById(show_div).style.display = 'none';
        document.getElementById(bg_div).style.display = 'none';
    }
</script>
</body>
</html>